﻿#include "../../edit/caret.h"
#include "../../x/draw/draw.h"

namespace swui
{
	void _draw_caret(_ctlInterior::drawInfo* info, _ctlInterior::caret* caret, ctlRoot* root)
	{
		if(caret->display() && root->getFocus() == root)
		{
			ctlPoint pt1 = caret->getPos();
			pt1.x += root->getLeft();
			pt1.y += root->getTop();
			HGDIOBJ hOld = SelectObject(info->hDC, caret->getObject());
			MoveToEx(info->hDC, pt1.x, pt1.y, 0);
			ctlPoint pt2 = pt1;
			pt2.y += caret->getLength();
			if(pt2.y > root->getBottom())
				pt2.y = root->getBottom();
			if(pt2.y > pt1.y)
				LineTo(info->hDC, pt2.x, pt2.y);
			SelectObject(info->hDC, hOld);
		}
	}

	void _ctlInterior::caret::setColor(ctlColor c)
	{
		DeleteObject(hPen);
		hPen = CreatePen(PS_SOLID, 1, MAKE_SYSTEM_RGB(c));
	}
}